package com.tanjun.thirdservice.web.service.wx.impl;

import com.alibaba.fastjson2.TypeReference;
import com.tanjun.common.enums.Method;
import com.tanjun.thirdservice.web.service.wx.WxService;
import com.tanjun.thirdservice.web.service.wx.WxUserService;
import com.tanjun.thirdservice.web.service.wx.request.WxCodeToPhoneRequest;
import com.tanjun.thirdservice.web.service.wx.request.WxCodeToUserRequest;
import com.tanjun.thirdservice.web.service.wx.response.WxCode2PhoneResponse;
import com.tanjun.thirdservice.web.service.wx.response.WxCode2UserResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class WxUserServiceImpl implements WxUserService {
    @Autowired
    private WxService wxService;

    @Override
    public WxCode2UserResponse jscode2session(WxCodeToUserRequest request) {
        request.setAppid(wxService.getAppid());
        request.setSecret(wxService.getSecret());
        return wxService.doRequest(wxService.getBaseUrl() + "sns/jscode2session", Method.GET, request, new TypeReference<WxCode2UserResponse>() {
        });
    }

    /**
     * 微信用户code获取用户基本信息接口
     *
     * @param request
     * @return
     */
    @Override
    public WxCode2PhoneResponse getPhoneNumber(WxCodeToPhoneRequest request) {
        return wxService.doRequestWithToken(wxService.getBaseUrl() + "wxa/business/getuserphonenumber",
                Method.POST, request, new TypeReference<WxCode2PhoneResponse>() {
                });
    }
}
